package com.nslt.dao;

import com.nslt.entity.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Repository
@Transactional
public class UsersDaoImpl implements UsersDao{

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public List<Users> findAllUsers(){

        List<Users> users = new ArrayList<Users>();
        String sql="select * from users";
        try {
            users=jdbcTemplate.query(sql,new BeanPropertyRowMapper<Users>(Users.class));
        }catch (Exception e){
            System.out.println(e);
            users = null;
        }
        return users;
    }
}
